﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BaiTu.DTOS;

namespace BaiTu.BLL
{
    /// <summary>
    /// Repository 泛型实现类
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public abstract class Repository<T> : IBLL.IBaseBLL<T>
        where T : BaseDTO
    {

        public IOCServices.IEngine CurrentEngineContext
        {
            get
            {
                return IOCServices.EngineContext.Current;
            }
        }
        private Domains.BaseDomain domainEntity = null;

        private IDAL.IRepository<Domains.BaseDomain> _baseRepository;
        public Repository() { }
        public Repository(IDAL.IRepository<Domains.BaseDomain> baseRepository)
        {
            _baseRepository = baseRepository;
        }
        public Domains.BaseDomain TypeDtoToDomainConvert(Domains.BaseDomain domain, DTOS.BaseDTO baseDTO)
        {
            if (domainEntity == null)
            {
                domainEntity = Activator.CreateInstance<Domains.BaseDomain>();
            }
            Common.Helpers.TypeConverterHelper.ConvertSourceToDest(domain, baseDTO);
            return domain;
        }
        public DTOS.BaseDTO TypeDomainToDTOConvert(Domains.BaseDomain domain, DTOS.BaseDTO baseDTO)
        {
            if (baseDTO == null)
            {
                baseDTO = Activator.CreateInstance<DTOS.BaseDTO>();
            }
            Common.Helpers.TypeConverterHelper.ConvertSourceToDest(baseDTO, domain);
            return baseDTO;
        }
        public virtual BaiTu.Framework.InnerResult Add(T entity)
        {
            throw new NotSupportedException("必须在子类重载");
        }

        public virtual BaiTu.Framework.InnerResult Delete(T entity)
        {
            throw new NotSupportedException("必须在子类重载");
        }

        public virtual BaiTu.Framework.InnerResult Update(T entity)
        {
            throw new NotSupportedException("必须在子类重载");
        }


        public virtual T FindByID(string id)
        {
            throw new NotSupportedException("必须在子类重载");
        }

        public virtual int GetCount()
        {
            throw new NotSupportedException("必须在子类重载");
        }


        public virtual long GetLongCount()
        {
            throw new NotSupportedException("必须在子类重载");
        }
    }
}
